﻿using System;

namespace NodeJS.http
{
    using NodeJS.net;
    using NodeJS.stream;
    /// <summary>
    /// An IncomingMessage object is created by http.Server or http.ClientRequest and passed as the first argument to the 'request' and 'response' event respectively.
    /// It may be used to access response status, headers and data.
    /// </summary>
    public abstract class IncomingMessage : Readable
    {
        /// <summary>
        /// Indicates that the underlaying connection was terminated before response.end() was called or able to flush.
        /// Just like 'end', this event occurs only once per response. See [http.ServerResponse]'s 'close' event for more information.
        /// </summary>
        [EvalAtCompile(Value = "close")]
        public new const NodeEvent CLOSE = null;

        /// <summary>
        /// <para>In case of server request, the HTTP version sent by the client.</para>
        /// <para>In the case of client response, the HTTP version of the connected-to server. Probably either '1.1' or '1.0'.</para>
        /// Also response.httpVersionMajor is the first integer and response.httpVersionMinor is the second.
        /// </summary>
        public readonly string HttpVersion;

        /// <summary>
        /// The request/response headers object.
        /// Read only map of header names and values. Header names are lower-cased.
        /// </summary>
        public readonly object Headers;

        /// <summary>
        /// The request/response trailers object. Only populated after the 'end' event.
        /// </summary>
        public object Trailers;

        /// <summary>
        /// Calls message.connection.setTimeout(msecs, callback).
        /// </summary>
        /// <param name="msecs"></param>
        /// <param name="callback"></param>
        public void SetTimeout(long msecs, Action callback)
        {
        }

        /// <summary>
        /// Only valid for request obtained from http.Server.
        /// The request method as a string. Read only. Example: 'GET', 'DELETE'.
        /// </summary>
        public readonly string Method;


        /// <summary>
        /// Only valid for request obtained from http.Server.
        /// Request URL string. This contains only the URL that is present in the actual HTTP request. If the request is:
        /// If you would like to parse the URL into its parts, you can use require('url').parse(request.url)
        /// If you would like to extract the params from the query string, you can use the require('querystring').parse function, or pass true as the second argument to require('url').parse
        /// </summary>
        public string Url;

        /// <summary>
        /// Only valid for response obtained from http.ClientRequest.
        /// The 3-digit HTTP response status code. E.G. 404.
        /// </summary>
        public int StatusCode;

        /// <summary>
        /// The net.Socket object associated with the connection.
        /// With HTTPS support, use request.connection.verifyPeer() and request.connection.getPeerCertificate() to obtain the client's authentication details.
        /// </summary>
        public Socket Socket;
    }
}
